package com.example.admin.yuejian21.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.admin.yuejian21.Bean.Activity;
import com.example.admin.yuejian21.Bean.ActivityDetail;
import com.example.admin.yuejian21.Model.ActivityModel;
import com.example.admin.yuejian21.R;

import it.sephiroth.android.library.picasso.Picasso;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ActivityDetailActivity extends AppCompatActivity {

    private ImageView activityPhoto,btn_back;
    private TextView activityIntro, activitytime, activityplace, activityname, activityprice, activityrenshu;
    private LinearLayout activity_baoming;
    private String activity_id,address;
    private ActivityDetail activityDetail;
    private Context mContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity_detail);
        initViews();
        initEvents();
        initData();

    }

    private void initViews() {
        activityPhoto = (ImageView) findViewById(R.id.activityPhoto);
        activityIntro = (TextView) findViewById(R.id.activityIntro);
        activityprice = (TextView) findViewById(R.id.activity_price);
        activityplace = (TextView) findViewById(R.id.activity_place);
        activitytime = (TextView) findViewById(R.id.activity_time);
        activity_baoming = (LinearLayout) findViewById(R.id.activity_baoming);
        activityrenshu = (TextView) findViewById(R.id.activity_renshu);
        activityname = (TextView) findViewById(R.id.activity_name);
        btn_back = (ImageView) findViewById(R.id.btn_back);
    }

    private void initEvents() {
        activity_baoming.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(ActivityDetailActivity.this, BaoMingActivity.class);
                i.putExtra("act_id", activity_id);
                i.putExtra("aduprice", activityDetail.getActivity_price());
               i.putExtra("stuprice", activityDetail.getActivity_price_stu());
                startActivity(i);
            }
        });
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initData() {
        Intent intent = getIntent();
        activity_id = intent.getStringExtra("activity_id");
        showData();
    }

    private void showData() {
        ActivityModel activityModel = new ActivityModel();
        Call<ActivityDetail> call = activityModel.getactivityDetail(activity_id);
        call.enqueue(new Callback<ActivityDetail>() {
            @Override
            public void onResponse(Call<ActivityDetail> call, Response<ActivityDetail> response) {
                activityDetail = response.body();
                activitytime.setText("活动时间：" + activityDetail.getUpdate_time());
                activityname.setText(/*"活动名称："+ */activityDetail.getActivity_name());
                activityIntro.setText("活动简介：" + activityDetail.getIntroduction());
                activityplace.setText("活动地址：" + activityDetail.getProvince_name() + "" + activityDetail.getCity_name() + "" + activityDetail.getPlace());
                activityprice.setText("活动费用：" + activityDetail.getActivity_price());
                activityrenshu.setText("已报名人数：" + activityDetail.getSign_num() + "人");

                String address = "http://172.24.10.175/workout/Uploads/" + activityDetail.getThumb();
                if (!activityDetail.getThumb().equals("")) {
                    Picasso.with(mContext).load(address).into(activityPhoto);
                }
            }

            /**/
            @Override
            public void onFailure(Call<ActivityDetail> call, Throwable t) {

            }
        });
    }
}

